import matplotlib.pyplot as plt
import numpy as np

hn, wn = 5, 5
threshold = 1

# saliencyPath = "D:/VR_project/ViewPrediction/frames/attentionSaliency/1-Skiing.npy"
# saliency_array = np.load(saliencyPath, allow_pickle=True)
# real_image = saliency_array[0]
# plt.imshow(real_image)
# plt.show()

def return_size(H, W):
    gblur_size_width, gblur_size_high = 3 * (W // wn) // 2,  3 * (H // hn) // 2

    if gblur_size_width % 2 == 0:
        gblur_size_width += 1
    if gblur_size_high % 2 == 0:
        gblur_size_high += 1

    return gblur_size_width, gblur_size_high



def return_matrix(image):
    split_image = np.zeros((hn, wn), dtype='int32')

    h, w = image.shape
    ht, wt = h // hn, w // wn
    thresTiles = ht * wt // ((hn + wn) // 2)

    ht_list = [ht * i for i in range(hn)] + [h]
    wt_list = [wt * i for i in range(wn)] + [w]

    for i in range(hn):
        for j in range(wn):
            matrix = (image[ht_list[i]:ht_list[i+1], wt_list[j]:wt_list[j+1]] == threshold)
            # print(sum(map(sum, (matrix == 1))), end=' ')
            if sum(map(sum, (matrix == 1))) > thresTiles:
                split_image[i, j] = 1
        # print()
    return split_image

def return_real_matrix(image):
    split_image = np.zeros((hn, wn), dtype='int32')

    h, w = image.shape
    ht, wt = h // hn, w // wn
    thresTiles = ht * wt // ((hn + wn) // 2)

    ht_list = [ht * i for i in range(hn)] + [h]
    wt_list = [wt * i for i in range(wn)] + [w]

    for i in range(hn):
        for j in range(wn):
            matrix = (image[ht_list[i]:ht_list[i+1], wt_list[j]:wt_list[j+1]] == threshold)
            # print(sum(map(sum, (matrix == 1))), end=' ')
            if sum(map(sum, (matrix == 1))) > 5:
                split_image[i, j] = 1
        # print()
    return split_image

# x = return_matrix(real_image)
# print(x)